package com.neuedu.vuejsserver.controller;

import com.alibaba.fastjson.JSON;
import com.neuedu.entity.Dept;
import com.neuedu.vuejsserver.domain.Page;
import com.neuedu.vuejsserver.service.DeptService;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * 项目：      jweb
 * 类名:       DeptController
 * 创建时间：  2023/11/24 14：03
 * 描述 :
 * 作者 :     张金山
 * QQ :     314649444
 * Site:      https://jshand.gitee.io
 *
 *   http://127.0.0.1:8080/server/dept?_type=list
 */
@WebServlet("/dept")
public class DeptController extends BaseController   {

    DeptService deptService = new DeptService();




    protected void deleteById(HttpServletRequest req, HttpServletResponse resp) throws IOException {
        boolean success = deptService.deleteById(req);

        Map result  = new HashMap();
        result.put("success",success);

        super.writeJSON(resp,result);
    }

    /**
     * 保存   http://127.0.0.1:8080/server/dept?_type=save&deptno=60&dname=Test&loc=TestLoc
     * @param req
     * @param resp
     * @throws ServletException
     * @throws IOException
     */
    protected void save(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        boolean success = deptService.save(req);

        Map result  = new HashMap();
        result.put("success",success);

        super.writeJSON(resp,result);
    }

    protected void update(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        boolean success = deptService.update(req);

        Map result  = new HashMap();
        result.put("success",success);

        super.writeJSON(resp,result);
    }
    protected void queryById(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        Dept dept = deptService.queryById(req);
        //将数据响应成json字符串
        super.writeJSON(resp,dept);
    }

    protected void list(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        Page page = deptService.queryList(req);
        //total
//


        // list   --  json  字符
        super.writeJSON(resp,page);
    }
    protected void test(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {

        System.out.println("DeptController.test");
    }

    protected void download(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {

        System.out.println("DeptController.download");
    }



}
